package com.markus.code.exam.tongcheng58;

import com.markus.code.图.图1.Node;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/14 20:43
 * todo:
 */
public class Main1 {
    public static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        public TreeNode(int val){
            this.val = val;
        }
    }
    /**
     *
     * @param node TreeNode类
     * @return int整型ArrayList<ArrayList<>>
     */
    public ArrayList<ArrayList<Integer>> printNode (TreeNode node) {
        // write code here
        ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
        if (node == null){
            return ans;
        }
        Deque<TreeNode> deque = new LinkedList<>();
        deque.add(node);
        while(!deque.isEmpty()){
            int size = deque.size();
            ArrayList<Integer> list = new ArrayList<>();
            for (int i=0;i<size;i++){
                TreeNode treeNode = deque.poll();
                if (treeNode.left != null){
                    deque.addLast(treeNode.left);
                }
                if (treeNode.right != null){
                    deque.addLast(treeNode.right);
                }
                list.add(treeNode.val);
            }
            ans.add(list);
        }
        return ans;
    }

    public static void main(String[] args) {

    }
}
